<template>
  <div class="app-container">
    <el-form :inline="true" :model="listQuery" class="demo-form-inline" @submit.native.prevent>
      <el-form-item label="投诉状态">
        <el-select
          class="toolbar-lable-right"
          v-model="listQuery.q_state"
          placeholder="请选择" size="small"
        >
          <el-option
            v-for="item in sellerComplaint"
            :label="item.name"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="用户名">
        <el-input v-model="listQuery.q_userName" size="small"></el-input>
      </el-form-item>
      <el-form-item label="商家">
        <el-select
          class="toolbar-lable-right"
          v-model="listQuery.q_sellerId"
          placeholder="请选择"
          size="small"
        >
          <el-option
            v-for="item in sellers"
            :label="item.name"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="this.getList">查询</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="reset">重置</el-button>
      </el-form-item>
    </el-form>

    <div class="button-table-margin">
      <el-button size="small" type="primary" @click="details" v-permission="['admin/order/complaint/details']">详情</el-button>
      <el-button size="small" type="primary" @click="doAudit" v-permission="['admin/order/complaint/doAudit']">审核</el-button>
      <el-button size="small" type="primary" @click="resetAudit" v-permission="['admin/order/complaint/doreset']">重置</el-button>
    </div>
    <el-table
      ref="singleTable"
      v-loading="listLoading"
      :data="dataList"
      border
      fit
      highlight-current-row
      @current-change="handleCurrentChange"
      style="width: 100%">
      <el-table-column type="index" align="center" width="50"></el-table-column>
      <el-table-column label="商品名称" width="400" show-overflow-tooltip>
        <template slot-scope="scope">
          <div>
          <img width="80" height="80" :src="$imagePath+scope.row.masterImg" style="vertical-align: middle;">
          {{ scope.row.orderProductName }}
          </div>
        </template>
      </el-table-column>
      <el-table-column property="sellerName" width="150" label="被投诉商家"></el-table-column>
      <el-table-column property="orderSn" width="200" label="订单号"></el-table-column>
      <el-table-column property="userName" width="120" label="投诉人账户名"></el-table-column>
      <el-table-column property="content" width="300" label="投诉内容"></el-table-column>
      <el-table-column property="image" width="150" label="投诉图片">
        <template slot-scope="scope">
          <img width="80" height="80" :src="$imagePath+scope.row.image" style="vertical-align: middle;">
        </template>
      </el-table-column>
      <el-table-column property="complaintTime" width="200" label="投诉时间"></el-table-column>
      <el-table-column property="source" width="150" label="投诉来源"></el-table-column>
      <el-table-column property="state" width="150" label="投诉状态">
        <template slot-scope="scope">
          {{ codeBox.SELLER_COMPLAINT[scope.row.state] }}
        </template>
      </el-table-column>
      <el-table-column property="sellerCompContent" width="300" label="商家申诉内容"></el-table-column>
      <el-table-column property="sellerComplaintTime" width="200" label="商家申诉时间"></el-table-column>
      <el-table-column property="optContent" width="300" label="平台处理结果"></el-table-column>

      <el-table-column fixed="right" label="操作" width="100" align="center">
        <template slot-scope="scope">
          <el-button @click="detailsRow(scope.row.id)" type="text" size="small">详情</el-button>
          <el-button @click="doAuditRow(scope.row)" type="text" size="small">审核</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
  </div>
</template>

<script>
import { listComplaint, auditPageComplaint, getSellers } from '@/api/orderafter'
import Pagination from '@/components/Pagination'
import { Message } from 'element-ui'
import { getCodeManager,codeToArray} from '@/api/all'
export default {
  name: 'complaintlist',
  components: { Pagination },
  data() {
    return {
      dataList: [],
      sellerComplaint: [],
      sellers: [],
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20,
        q_state: '',
        q_userName: '',
        q_sellerId: ''
      }
    }
  },
  created() {
    getCodeManager('SELLER_COMPLAINT', () => {
      this.sellerComplaint = codeToArray('SELLER_COMPLAINT');
    })
    this.getList()
    getSellers().then(response => {
      this.sellers=[
        ...response.data.rows.map((item)=>{return  {
          name:item.sellerName,
          value:item.id
        }})
      ]
    })
  },
  methods:{
    handleCurrentChange(val) {
      // 选中当前行数据
      this.currentRow = val
    },
    // 获取列表数据
    getList() {
      this.listLoading = true
      listComplaint(this.listQuery).then(response => {
        this.dataList = response.data.rows
        this.total = response.data.total
        this.listLoading = false
      })
    },
    reset() {
      this.listQuery = {
        page: 1,
        limit: 20,
        q_state: '',
        q_userName: '',
        q_sellerId: ''
      }
      this.getList()
    },
    details() {
      if(this.currentRow == null) {
        Message.error('请选择一条记录')
        return
      }
      this.$router.push({
        path: "/orderafter/complaintdetails",
        query: { id: this.currentRow.id }
      });
    },
    doAudit() {
      if(this.currentRow == null) {
        Message.error('请选择一条记录')
        return
      }
      if(this.currentRow.state != 1 && this.currentRow.state != 4) {
        Message.error('买家投诉待审核或者卖家申诉待审核,平台才可以处理')
        return
      }
      this.$router.push({
        path: "/orderafter/complaintaudit",
        query: { id: this.currentRow.id }
      });
    },
    detailsRow(id){
      this.$router.push({
        path: "/orderafter/complaintdetails",
        query: { id: id }
      });
    },
    doAuditRow(currentRowDo){
      if(currentRowDo.state != 1 && currentRowDo.state != 4) {
        Message.error('买家投诉待审核或者卖家申诉待审核,平台才可以处理')
        return
      }
      this.$router.push({
        path: "/orderafter/complaintaudit",
        query: { id: currentRowDo.id }
      });
    },
    resetAudit() {
      if(this.currentRow == null) {
        Message.error('请选择一条记录')
        return
      }
      if(this.currentRow.state == 1 || this.currentRow.state == 4) {
        Message.error('该投诉信息待审核状态，不能进行重置操作')
        return
      }
      this.$router.push({
        path: "/orderafter/complaintreset",
        query: { id: this.currentRow.id }
      });

    }

  }
}
</script>

<style>
</style>
